package com.scu.hotelsystem.controller;

import com.scu.hotelsystem.service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpSession;

@Controller
public class ManagerController {
    @Autowired
    private ManagerService managerService;


    @RequestMapping("/verifyManagerLogin")
    public ModelAndView verifyLogin(RedirectAttributes redirectAttributes, HttpSession httpSession,
                              @RequestParam("account") String account,
                              @RequestParam("password") String password){
        ModelAndView view;
        int id;

        view = new ModelAndView();
        id = managerService.verifyLogin(account, password);
        if (id == managerService.FAILED){
            redirectAttributes.addFlashAttribute("tip", "账户或密码错误");
            view.setViewName("redirect:login");
        }else {
            httpSession.setAttribute("managerId", id);
            view.setViewName("redirect:managerIndex");
        }
        return view;
    }

    @RequestMapping("managerIndex")
    public String managerIndex(){
        return "managerindex";
    }



}
